/**
 * 恰好做如下操作：选一个元素整除2，再选一个元素（可以相同）乘2
 * 求如此操作之后的最小的陡峭值。
 * 分几种情况分别枚举即可：
 * 1. 均在同一个元素上操作；
 * 2. 在连续的2个元素上操作，除乘、乘除
 * 3. 两个操作互不影响，分别记录，取出前若干个最大的，再枚举一下
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vll = vector<llt>;

template<typename T>
void input(vector<T>&v, int n){
    v.assign(n + 1, {});
    for(int i=1;i<=n;++i) cin >> v[i];
}

template<typename T>
istream & operator >> (istream & is, vector<T> & v){
    for(auto & i : v) is >> i;
    return is;
}

llt const INF = 0x1F2F3F4F5F6F7F8F;
llt const NINF = -INF;
llt const MOD = 998244353LL;

int N;
vector<llt> A;

llt procSame(){
    llt cha = NINF;
    for(int i=0;i<N;++i){
        auto origin = A[i];
        auto tmp = origin / 2 * 2;
        if(tmp == origin) continue;

        llt prev = 0;
        llt now = 0;
        if(i > 0){
            prev += abs(origin - A[i - 1]);
            now += abs(tmp - A[i - 1]);
        }      
        if(i + 1 < N){
            prev += abs(origin - A[i + 1]);
            now += abs(tmp - A[i + 1]);
        }
        
        cha = max(cha, prev - now);
    }        
    return cha;
}

llt procDM(){
    llt cha = NINF;
    for(int i=0;i+1<N;++i){
        auto oa = A[i], ob = A[i + 1];
        auto ta = oa / 2, tb = ob * 2;
        
        llt pre = abs(ob - oa), now = abs(tb - ta);
        if(i > 0){
            pre += abs(oa - A[i - 1]);
            now += abs(ta - A[i - 1]);
        }
        if(i + 2 < N){
            pre += abs(ob - A[i + 2]);
            now += abs(tb - A[i + 2]);
        }
        cha = max(cha, pre - now);
    }
    return cha;
}

llt procMD(){
    llt cha = NINF;
    for(int i=0;i+1<N;++i){
        auto oa = A[i], ob = A[i + 1];
        auto ta = oa * 2, tb = ob / 2;
        
        llt pre = abs(ob - oa), now = abs(tb - ta);
        if(i > 0){
            pre += abs(oa - A[i - 1]);
            now += abs(ta - A[i - 1]);
        }
        if(i + 2 < N){
            pre += abs(ob - A[i + 2]);
            now += abs(tb - A[i + 2]);
        }
        cha = max(cha, pre - now);
    }
    return cha;
}

llt procSep(){
    vector<pair<llt, int>> divide(N, {0LL, 0});
    for(int i=0;i<N;++i){
        auto o = A[i];
        auto t = o / 2;
        llt pre = 0;
        llt now = 0;
        if(i > 0){
            pre += abs(o - A[i - 1]);
            now += abs(t - A[i - 1]);
        }
        if(i + 1 < N){
            pre += abs(o - A[i + 1]);
            now += abs(t - A[i + 1]);
        }
        divide[i] = {pre - now, i};
    }    
    sort(divide.begin(), divide.end(), [](const pair<llt, int> & a, const pair<llt, int> & b){
        if(a.first != b.first) return a.first > b.first;
        return a.second < b.second;
    });

    vector<pair<llt, int>> multi(N, {0LL, 0});
    for(int i=0;i<N;++i){
        auto o = A[i];
        auto t = o * 2;
        llt pre = 0;
        llt now = 0;
        if(i > 0){
            pre += abs(o - A[i - 1]);
            now += abs(t - A[i - 1]);
        }
        if(i + 1 < N){
            pre += abs(o - A[i + 1]);
            now += abs(t - A[i + 1]);
        }
        multi[i] = {pre - now, i};
    }    
    sort(multi.begin(), multi.end(), [](const pair<llt, int> & a, const pair<llt, int> & b){
        if(a.first != b.first) return a.first > b.first;
        return a.second < b.second;
    });

    llt ans = NINF;
    for(int i=0;i<min(10, N);++i){
        auto c1 = divide[i].first;
        auto p = divide[i].second;

        int k = 0;
        while(k < N and multi[k].second == p or multi[k].second == p + 1 or multi[k].second == p - 1) ++k;
        if(k == N) continue;

        ans = max(ans, c1 + multi[k].first);
    }
    return ans;
}

void work(){
    cin >> N;
    A.assign(N, {});
    cin >> A;
    llt ans = 0;
    for(int i=1;i<N;++i){
        ans += abs(A[i] - A[i - 1]);
    }

#ifndef ONLINE_JUDGE
    cout << "origin = " << ans << endl;
#endif

    llt sameCha = procSame();

#ifndef ONLINE_JUDGE
    cout << "same = " << sameCha << endl;
#endif    

    llt dmCha = procDM();

#ifndef ONLINE_JUDGE
    cout << "dm = " << dmCha << endl;
#endif   

    llt mdCha = procMD();

#ifndef ONLINE_JUDGE
    cout << "md = " << mdCha << endl;
#endif  

    llt sepCha = procSep();

    vector<llt> vec {sepCha, sameCha, dmCha, mdCha};
    auto cha = *max_element(vec.begin(), vec.end());

    cout << ans - cha << endl;
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase; 
    while(nofkase--) work();    
    return 0;
}
